package com.burry.action;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.List;

import net.sf.json.JSONObject;

import applelew.util.Debug;

import com.burry.bo.JSONResult;
import com.burry.services.SizeService;

public class SizeAction extends BaseAction {

	private InputStream inputStream;
	private String pid;
	private String content;
	private String descibe;

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getDescibe() {
		return descibe;
	}

	public void setDescibe(String descibe) {
		this.descibe = descibe;
	}

	public String getPid() {
		return pid;
	}

	public void setPid(String pid) {
		this.pid = pid;
	}

	public String sizeList() {
		SizeService ss = new SizeService();
		List sizeList = ss.getAllSizeInfo();
		
		JSONResult json = new JSONResult(sizeList);
		JSONObject jsonRet = JSONObject.fromObject(json);  
		String allSize = jsonRet.toString();

		try {
			setInputStream(new ByteArrayInputStream(allSize.getBytes("utf-8")));
		} catch (UnsupportedEncodingException e) {
			Debug.logError(e.getMessage());
		}

		return SUCCESS;
	}
	
	public String sizeDetailList(){
		SizeService ss = new SizeService();
		List sizeList = ss.getSizeDetail(pid);
		
		JSONResult json = new JSONResult(sizeList);
		JSONObject jsonRet = JSONObject.fromObject(json);  
		String allSize = jsonRet.toString();

		try {
			setInputStream(new ByteArrayInputStream(allSize.getBytes("utf-8")));
		} catch (UnsupportedEncodingException e) {
			Debug.logError(e.getMessage());
		}

		return SUCCESS;
	}
	
	public String addASize(){
		SizeService ss = new SizeService();
		ss.addASize(pid, content, descibe);
		return SUCCESS;
	}

	public InputStream getInputStream() {
		return inputStream;
	}

	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}
}
